package com.xunqi.util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DateUtil {
	private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;

	/**
	 * 生产beforeNumber天前的日期
	 * 
	 * @param beforeNumber
	 * @return
	 */
	public static String genBeginDate(int beforeNumber) {
		return LocalDate.now().minusDays(beforeNumber).format(formatter);
	}

	/**
	 * 生产beforeNumber天前后一天的日期
	 * 
	 * @param beforeNumber
	 * @return
	 */
	public static String genBeginDateThen(int beforeNumber) {
		return LocalDate.now().minusDays(beforeNumber - 1).format(formatter);
	}

	public static void main(String[] args) {

		LocalDate localDate = LocalDate.now();
		System.out.println(localDate.format(formatter));
		for (int querybeginNum = 3; querybeginNum > 0; querybeginNum--) {
			System.out.printf("beginDate,endDate:[%s,%s]\n", genBeginDate(querybeginNum),
					genBeginDateThen(querybeginNum));
		}
		System.out.println("2018-01-09".compareTo("2018-01-09"));
	}

}
